<!--
 * @FilePath     : /study_code/vue2.x/transition-sync.html
 * @Description  : 一个动态过渡的示例
 * @Date         : 2025-05-03 08:48:12
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-03 08:48:12
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="app">
      Fade In:
      <input type="range" v-model="fadeInDuration" min="0" v-bind:max="maxFadeDuration" />
      Fade Out:
      <input type="range" v-model="fadeOutDuration" min="0" v-bind:max="maxFadeDuration" />
      <transition
        v-bind:css="false"
        v-on:before-enter="beforeEnter"
        v-on:enter="enter"
        v-on:leave="leave"
      >
        <p v-if="show">hello</p>
      </transition>
      <button v-if="stop" v-on:click="stop = false; show = false">Start animating</button>
      <button v-else v-on:click="stop = true">Stop it!</button>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>
    <script>
      // 自定义组件
      const myComponent = {
        data: function () {
          return {}
        },
        props: [],
        template: ``,
        methods: {},
      }

      var app = new Vue({
        el: '#app',
        data: function () {
          return {
            show: true,
            fadeInDuration: 1000,
            fadeOutDuration: 1000,
            maxFadeDuration: 1500,
            stop: true,
          }
        },
        mounted: function () {
          this.show = false
        },
        methods: {
          beforeEnter: function (el) {
            // el就是过渡组件的被控元素
            console.log(el)
            el.style.opacity = 0
          },
          enter: function (el, done) {
            var vm = this
            Velocity(
              el,
              { opacity: 1 },
              {
                duration: this.fadeInDuration,
                complete: function () {
                  done()
                  if (!vm.stop) vm.show = false
                },
              }
            )
          },
          leave: function (el, done) {
            var vm = this
            Velocity(
              el,
              { opacity: 0 },
              {
                duration: this.fadeOutDuration,
                complete: function () {
                  done()
                  vm.show = true
                },
              }
            )
          },
        },
      })
    </script>
  </body>
</html>
